<?php
class SecoesController extends AppController {

	var $name = 'Secoes';
	var $helpers = array('Html', 'Form', 'CakePtbr.Formatacao');

	function index($slug) {
            $secao = $this->Secao->findBySlug($slug);

            $this->set('secao', $secao);
            $this->set('secaoAtual', $secao['Secao']['slug']);
	}

	function admin_index() {
		$this->Secao->recursive = 0;
		$this->set('secoes', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Secao.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('secao', $this->Secao->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Secao->create();
			if ($this->Secao->save($this->data)) {
				$this->Session->setFlash(__('The Secao has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Secao could not be saved. Please, try again.', true));
			}
		}
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Secao', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Secao->save($this->data)) {
				$this->Session->setFlash(__('The Secao has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Secao could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Secao->read(null, $id);
		}
	}

}
?>